var basePath = getBasePath(); 
var modelName = "公告信息";
var tableObject = $("#approvalChainList");
$(function(){
	  //显示权限按钮
	  var parentUUID = $("input[name='parentUUID']").val();
   	  $.permission.showButton(parentUUID,"actionBtnArea");
   	  
   	  //表格初始化
   	  var deleteFlag = $("input[name='deleteFlag']").val();
      var parentUUID = $("input[name='parentUUID']").val();
      var saveType = $("input[name='saveType']").val();
	  $.dataGridEasyUI.initTable({
		  pageId:"#approvalChainListPage",
		  gridId:"#approvalChainList",
		  url:getBasePath()+'approvalChain/getApprovalChainList.do',
		  toolbarId:"#approvalChainListPage .tb_toolbar",
		  queryParams: {
	        	deleteFlag:deleteFlag,
	        	parentUUID:parentUUID,
	        	saveType:saveType
	      },
		  columns:[[
	            {field:'id',checkbox:true},
	            {field:'uuid',title:'流程编号',width:'17%'},
	            {field:'typeName',title:'所属分类',width:'10%'},
	            {field:'title',title:'审批链名称',width:'25%',formatter: function(value,row,index){
  		  	    	return "<a href='javascript:showDetailList(\""+row.uuid+"\")' title='点我显示流程详情'>"+value+"</a>";
				}},
                {field:'editorName',title:'创建人',width:'10%'},
                {field:'editTime',title:'创建时间',width:'10%'}
	        ]]
	  });
  
  //新增按钮绑定事件
  $("#addDataLink").bind("click",function(){
	  window.location.href=getBasePath()+"manage/office/editApprovalChain.jsp";
	  /*$.dataGridEasyUI.initEditWindow({
		  url:getBasePath()+"manage/notice/editApprovalChain.jsp",
		  title:"添加"+modelName+"信息",
		  actionType:"add"
	  });*/
  });
  
  //更新按钮绑定事件
  $("#updateDataLink").bind("click",function(){
	  var curRow = tableObject.datagrid("getSelected");
	  if(curRow==null){
	  	 $.messager.alert('系统提示',"请先选择要编辑的行",'error');
	  	 return;
	  }
	  window.location.href=getBasePath()+"manage/office/editApprovalChain.jsp?id="+curRow.id;
	  /* $.dataGridEasyUI.initEditWindow({
		  url:getBasePath()+"manage/office/editApprovalChain.jsp?showType=window",
		  title:"编辑"+modelName+"",
		  actionType:"update",
		  width: 1000,
		  height: 535
	   });*/
  });
  
  //批量删除
  $("#batchDeleteLink").bind("click",function(){
	  $.dataGridEasyUI.batchDeleteData({
		  url:getBasePath()+"/approvalChain/batchDelApprovalChainForHS.do",
	  });
  });
  
  //单个删除
  $("#singleDeleteLink").bind("click",function(){
	  $.dataGridEasyUI.batchDeleteData({
		  url:getBasePath()+"/approvalChain/delApprovalChain.do",
	  });
  });


   //图片弹窗
	$(".fancybox-effects-a").fancybox({
		helpers: {
			title : {
				type : 'outside'
			},
			overlay : {
				speedOut : 0
			}
		}
	});
})

//查看详细信息
function showDetail(id){
  $.dataGridEasyUI.initEditWindow({
	  url:getBasePath() + "approvalChain/getApprovalChainDetail.do?id="+id,
	  title:"查看"+modelName+"明细",
	  actionType:"detail",
	  width: $(window).width()*0.95,
	  height: $(window).height()*0.95
  })
}

//查看详细信息
function showDetailList(uuid){
	$.dataGridEasyUI.initEditWindow({
		  url:basePath+"manage/office/approvalDetailList.jsp?uuid="+uuid+"",
		  title:"查看"+modelName+"明细",
		  actionType:"detail",
		  width: 650,
		  height: $(window).height()*0.85
	  })
	
	//验证是否登录--开始
  	if(!checkLoginStatus()){return;}
      //验证是否登录--结束
      
  	var editDataFormArea = $("#editDataFormArea");
		if(editDataFormArea.length==0){
			$("<div id='editDataFormArea'></div>").prependTo("body");
		}
		var _width = 650;
		var _height = $(window).height()*0.85;
		var x_left = ($(window).width()-_width)/2;
		var y_top = ($(window).height()-_height)/2;
		
		//href:basePath+"manage/rcbj/adminDetail.jsp",
		var uuidStr = uuid+"";
		console.log(uuidStr+"");
  	$("#editDataFormArea").window({
  	    title: '查看审批链明细',
  	    width: _width,
  	    height: "85%",
  	    iconCls:'icon-window',
  	    left:x_left,
  	    top:y_top,
  	    closed: false,
  	    cache: false,
  	    modal: true,
  	    onClose:function(){
		    $("#editDataFormArea").html("");
		    $("#editDataFormArea").remove();
		},
		href:basePath+"manage/office/approvalDetailList.jsp?uuid="+uuidStr+""
  	});
}

//审核信息
function checkSingleData(){
	$.dataGridEasyUI.initEditWindow({
		  url:getBasePath() + "manage/approvalChain/checkApprovalChain.jsp",
		  title:"审核"+modelName,
		  actionType:"check",
	      width: 650,
          height: 300
	});
}

//检索数据
function seachData(){
   var searChObj = new Object(); 
   var formId = "searchForm";
   $("#"+formId).find("input").each(function(i){
	   searChObj[$(this).attr("name")] = $(this).val();
   });
   
   $("#"+formId).find("select").each(function(i){
	   searChObj[$(this).attr("name")] = $(this).val();
   });
   tableObject.datagrid({
	     queryParams:searChObj
   })
}

//永久删除数据
function batchDelInDB(){
  $.dataGridEasyUI.batchDeleteInDB({
	  url:getBasePath()+"/approvalChainInfo/batchDelApprovalChain.do",
  });
}
         
         
 //恢复数据
function rebackData(){
	$.dataGridEasyUI.batchDeleteInDB({
		  url:basePath+"/approvalChainInfo/batchRebackData.do"
	});
}
